import { defineConfig, loadEnv } from "vite";
import vue from "@vitejs/plugin-vue";
import { fileURLToPath, URL } from "node:url";
import proxyConfig from "./src/config/proxy";

// https://vite.dev/config/
export default defineConfig(({ mode }) => {
  // 获取环境变量
  const env = loadEnv(mode, process.cwd(), "");

  return {
    plugins: [vue()],

    resolve: {
      alias: {
        "@": fileURLToPath(new URL("./src", import.meta.url)),
      },
    },

    // 开发服务器配置
    server: {
      port: 9090,
      https: false,
      host: "0.0.0.0",
      proxy: proxyConfig(env), // 代理规则
    },
  };
});
